package org.csu.mypetstore.persistence;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;
import org.csu.mypetstore.domain.Cart;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.List;

@Repository
public interface CartMapper  extends BaseMapper{
    @Insert("INSERT INTO cart VALUES(#{username},#{cart.itemid},#{cart.productid},#{cart.description},#{cart.quantity},#{cart.stock},#{cart.listprice},#{cart.total});")
    void insertCart(@Param("cart") Cart cart, @Param("username") String username);
    @Select("SELECT * FROM cart WHERE username=#{username};")
    List<Cart> getCartByusername(String username);
    @Select("SELECT * FROM cart WHERE username=#{username} AND itemid=#{itemid};")
    Cart getCartByusername2(@Param("username") String username, @Param("itemid") String itemid);
    @Delete(" DELETE FROM cart WHERE username=#{username};")
    void deletecart(String username);
    @Update("UPDATE cart SET quantity=#{quantity},total=#{total} WHERE username=#{username} AND itemid=#{itemid};")
    void Updatecart(@Param("username") String username, @Param("itemid") String itemid, @Param("quantity") int quantity, @Param("total") BigDecimal total);
    @Delete("DELETE FROM cart WHERE username=#{username} AND itemid=#{itemid};")
    void deletecartByusername_and_itemid(@Param("username") String username, @Param("itemid") String itemid);
    //综合性的方法
    @Select("select * from cart where username=#{username} AND itemid=#{itemid};")
    Cart isExist(@Param("username") String username, @Param("itemid") String itemid);
}
